<?php


namespace app\index\controller;


use app\admin\model\EngineeringCate;
use app\admin\model\Engineering as EngineeringModel;

class Engineering extends Base
{
    public function index()
    {
        $cate = EngineeringCate::where(['status'=>1])->limit(0,5)->order('sort asc')->select();
        $cate_id = input('cate_id',1);
        $type = $cate_id;
        $cate_name = EngineeringCate::find($cate_id);
        $engineering = EngineeringModel::where(['status'=>1,'cate_id'=>$cate_id])
            ->order('sort asc')
            ->paginate(6,false);
        $page = $engineering->render();
        return $this->view->fetch('',[
            'cate' => $cate,
            'cate_name' => $cate_name,
            'engineering' => $engineering,
            'page' => $page,
            'type' => $type,
        ]);
    }


    public function details()
    {
        $cate = EngineeringCate::where(['status'=>1])->limit(0,5)->order('sort asc')->select();
        $cate_id = input('cate_id',1);
        $cate_name = EngineeringCate::find($cate_id);
        $type = $cate_id;
        $id = input('id');
        $engineering = EngineeringModel::find($id);
        $upper = EngineeringModel::where('id', '<', $id)
            ->where('status', 1)
            ->order('id desc')
            ->find();   //上一条
        $lower = EngineeringModel::where('id', '>', $id)
            ->where('status', 1)
            ->order('id asc')
            ->find();   //下一条
        return $this->view->fetch('',[
            'cate' => $cate,
            'cate_name' => $cate_name,
            'engineering' => $engineering,
            'type' => $type,
            'cate_id' => $cate_id,
            'upper' => $upper,
            'lower' => $lower,
        ]);
    }
}